﻿// -------------------------------------------------------------------------------------------------------------------------------
// <copyright file="TestConstructorWithDataParameter.cs" company="Exul">
//     Copyright (c) Exul. All rights reserved.
// </copyright>
// <author>
//     Exul
// </author>
// -------------------------------------------------------------------------------------------------------------------------------

namespace ExulLibrary.Mathematics.LinearAlgebra.Tests.DenseSymmetricMatrixTest
{
    #region Usings

    using System;

    using ExulLibrary.Exceptions;

    using NUnit.Framework;

    #endregion

    /// <summary>
    ///     Test suite for the constructor with data parameter.
    /// </summary>
    [TestFixture]
    [Category("ExulLibrary.Mathematics.LinearAlgebra.DenseSymmetricMatrix{T}")]
    public sealed class TestConstructorWithDataParameter
    {
        /// <summary>
        ///     Tests the constructor when data parameter is not <see langword="null"/> or empty.
        /// </summary>
        /// <param name="length">
        ///     The length of data parameter.
        /// </param>
        /// <param name="expectedSize">
        ///     The expected size of the new matrix.
        /// </param>
        [Test]
        [TestCase(1, 1)]
        [TestCase(2, 1)]
        [TestCase(3, 2)]
        [TestCase(6, 3)]
        [TestCase(7, 3)]
        public void WhenDataParameterIsValid(int length, int expectedSize)
        {
            // Arrange
            var data = new object[length];

            // Act
            var matrix = new DenseSymmetricMatrix<object>(data);

            // Assert
            Assert.That(matrix.RowsCount, Is.EqualTo(expectedSize));
            Assert.That(matrix.ColumnsCount, Is.EqualTo(expectedSize));
            Assert.That(matrix.IsSquare, Is.True);
            Assert.That(matrix.Values, Is.SameAs(data));
        }

        #if SAFE

        /// <summary>
        ///     Tests the constructor when data parameter is <see langword="null"/>.
        /// </summary>
        [Test]
        public void WhenDataParameterIsNull()
        {
            // Act and Assert
            Assert.That(
                () => new DenseSymmetricMatrix<object>(null),
                Throws.TypeOf<ArgumentNullException>().With.Property("ParamName").EqualTo("data"));
        }

        /// <summary>
        ///     Tests the constructor when data parameter is empty collection.
        /// </summary>
        [Test]
        public void WhenDataParameterIsEmpty()
        {
            // Act and Assert
            Assert.That(
                () => new DenseSymmetricMatrix<object>(new object[0]),
                Throws.TypeOf<EmptyCollectionException>().With.Property("ParamName").EqualTo("data"));
        }

        #endif
    }
}